package com.iflytek.emp.web.controller.stu;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.iflytek.emp.common.annotation.Log;
import com.iflytek.emp.common.enums.BusinessType;
import com.iflytek.emp.system.domain.Stuinfo;
import com.iflytek.emp.system.service.IStuinfoService;
import com.iflytek.emp.common.core.controller.BaseController;
import com.iflytek.emp.common.core.domain.AjaxResult;
import com.iflytek.emp.common.utils.poi.ExcelUtil;
import com.iflytek.emp.common.core.page.TableDataInfo;

/**
 * 学生基础信息Controller
 * 
 * @author ruoyi
 * @date 2024-07-01
 */
@Controller
@RequestMapping("/system/stuinfo")
public class StuinfoController extends BaseController
{
    private String prefix = "system/stuinfo";

    @Autowired
    private IStuinfoService stuinfoService;

    @RequiresPermissions("system:stuinfo:view")
    @GetMapping()
    public String stuinfo()
    {
        return prefix + "/stuinfo";
    }

    /**
     * 查询学生基础信息列表
     */
    @RequiresPermissions("system:stuinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Stuinfo stuinfo)
    {
        startPage();
        List<Stuinfo> list = stuinfoService.selectStuinfoList(stuinfo);
        return getDataTable(list);
    }

    /**
     * 导出学生基础信息列表
     */
    @RequiresPermissions("system:stuinfo:export")
    @Log(title = "学生基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Stuinfo stuinfo)
    {
        List<Stuinfo> list = stuinfoService.selectStuinfoList(stuinfo);
        ExcelUtil<Stuinfo> util = new ExcelUtil<Stuinfo>(Stuinfo.class);
        return util.exportExcel(list, "学生基础信息数据");
    }

    /**
     * 新增学生基础信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生基础信息
     */
    @RequiresPermissions("system:stuinfo:add")
    @Log(title = "学生基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Stuinfo stuinfo)
    {
        return toAjax(stuinfoService.insertStuinfo(stuinfo));
    }

    /**
     * 修改学生基础信息
     */
    @RequiresPermissions("system:stuinfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Stuinfo stuinfo = stuinfoService.selectStuinfoById(id);
        mmap.put("stuinfo", stuinfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生基础信息
     */
    @RequiresPermissions("system:stuinfo:edit")
    @Log(title = "学生基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Stuinfo stuinfo)
    {
        return toAjax(stuinfoService.updateStuinfo(stuinfo));
    }

    /**
     * 删除学生基础信息
     */
    @RequiresPermissions("system:stuinfo:remove")
    @Log(title = "学生基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stuinfoService.deleteStuinfoByIds(ids));
    }
}
